package j02object;

import java.io.*;

/*
加菲猫,2,100;

123

 */

class Cat implements Serializable{
    String name;
    int age;

    public Cat(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Cat{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class J1 {
    public static void main(String[] args) throws Exception {
        ObjectOutputStream f = new ObjectOutputStream(
                new FileOutputStream("_1219\\src\\j02object\\a.txt")
        );
//        f.writeInt(12);
//        f.writeInt(66);
        //arraylist

        f.writeObject(new Cat("波斯猫",2));
        f.writeObject(new Cat("加菲猫",5));

        f.close();
    }
}

class J2read{
    public static void main(String[] args) throws Exception {
        ObjectInputStream f = new ObjectInputStream(
                new FileInputStream("_1219\\src\\j02object\\a.txt")
        );
//        System.out.println(f.readInt());
//        System.out.println(f.readInt());
//        System.out.println(f.readInt());
//        System.out.println(f.readInt());
        Cat c1 =(Cat)f.readObject();
        Cat c2 =(Cat)f.readObject();
        System.out.println("c1 = " + c1);
        System.out.println("c2 = " + c2);
    }
}